package com.sec.etech.ism.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sec.etech.ism.mapper.IsmServiceDefMapper;
import com.sec.etech.ism.model.IsmServiceDef;
import org.springframework.stereotype.Service;

@Service
public class IsmServiceDefService extends ServiceImpl<IsmServiceDefMapper, IsmServiceDef> {

    /**
     * 根据服务编码查询
     * @param serviceCode
     * @return
     */
    public IsmServiceDef getByCode(String serviceCode){
        IsmServiceDef serviceDef = this.baseMapper.selectOne(Wrappers.<IsmServiceDef>lambdaQuery()
                .eq(IsmServiceDef::getCode, serviceCode)
                .eq(IsmServiceDef::getActive, 1));
        return serviceDef;
    }

    /**
     * 根据ID或者分类、服务代码、类型获取
     * @param defId
     * @param serviceCode
     * @return
     */
    public IsmServiceDef getByIdOrCode(Long defId, String serviceCode){
        if(defId!=null && defId>0) {
            return this.baseMapper.selectById(defId);
        }else {
            return this.getByCode(serviceCode);
        }
    }
}
